<?php
class Core_Common_Cache {
	protected static $_instance = null;
	private $_cache;
	
	protected function __construct() {
			$config = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('memcache');
			$this->_cache = new Memcache() or null;
			$this->_cache->connect($config['host'],$config['port']);
	}
	
	public static function getInstance() {
		if(null===self::$_instance) {
			self::$_instance = new self(); 
		}
		return self::$_instance;
		
	}
	public function save($key,$value,$lifetime=1800) {
		$this->_cache->set($key,$value,false,$lifetime);
	}
	
	public function __get($name) {
		$value = $this->_cache->get($name) or null;
		if(isset($value) && $value!=false)
			return $value;
		else
			return null;
	}
	
	public function __set($name,$value) {
		$this->save($name, $value);
	}
}